package com.xh.audit.controller.project;

import com.xh.audit.entity.project.ProjectArchive;
import com.xh.audit.service.ProjectArchiveService;
import com.xh.common.R;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 * 项目档案表;项目归档/项目档案
 * 流程的关联到审计文书 ;
 * 档案的再关联文书;
 * 档案中关联的文书不让删,自上传的可以删;
 * 档案包含文书
 * 前端控制器
 * </p>
 *
 * @author lhl
 * @since 2023-10-19
 */
@RestController
@RequestMapping("/project-archive")
@RequiredArgsConstructor
@Validated
public class ProjectArchiveController {
    private final ProjectArchiveService projectArchiveService;

    @PostMapping("/save")
    public R<ProjectArchive> save(@RequestBody
                                  @Validated
                                  ProjectArchive tosave) {
        boolean saveFlag = projectArchiveService.saveOrUpdate(tosave);

        if (saveFlag) {
            return R.success(projectArchiveService.getById(tosave.getId()));
        }
        return R.failed("项目立项:保存失败");
    }


    /**
     * List<Integer> 集合验证 必须在类上也加 @Validated
     *
     * @param ids
     * @return
     */
    @PostMapping("/del")
    public R<ProjectArchive> del(@RequestBody
                                 @Validated
                                 @NotEmpty(message = "ids 集合不能空")
                                 List<Integer> ids) {
        R<ProjectArchive> res = projectArchiveService.del(ids);
        return res;
    }
}
